/**
Author: Lei Zhang
File Creation Date: Apr 22, 2014
Class Description:
*/
package MartaModeling;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

import genDevs.modeling.content;
import genDevs.modeling.message;
import GenCol.entity;
import simView.ViewableAtomic;
import simView.ViewableDigraph;

public class MartaSystem extends ViewableDigraph{

	private ArrayList<MartaStation> stationList;
	
	public MartaSystem (String name) {
		super(name);
		stationList = new ArrayList<MartaStation>();
		this.initSys();
	}
	
	public MartaSystem() {
		this("MartaSystem");
	}
	
	private void initSys() {
		MartaScheduler center = new MartaScheduler("Schedule Center");
		
		Receiver r = new Receiver("DemoMsg");
		this.add(r);
		this.add(center);

		
		for(int i=1; i<=MartaConst.NUM_OF_STATIONS;i++) {
			MartaStation s ;
			//suburban stations
			if(i<MartaConst.NUM_OF_STATIONS*0.25 || i >= MartaConst.NUM_OF_STATIONS*0.75) {
				s = new MartaStation(i,StationType.SUBRAN_STATION,center.getWaitingQ(i));
			} else {
				s = new MartaStation(i,StationType.URBAN_STATION,center.getWaitingQ(i));
			}
			this.stationList.add(s);
			this.add(s);
		}
		
		
		//connect first station throught the lastone
		for(int i=0; i< stationList.size()-1;i++){
			//s = stationList.get(i);
			String upStreamPort = MartaConst.STATION_MODEL_OUT_PORT_NAME_PREFIX + stationList.get(i).getStationNum();
			String downStreamPort = MartaConst.STATION_MODEL_IN_PORT_NAME_PREFIX + stationList.get(i+1).getStationNum();
			this.addCoupling(stationList.get(i), upStreamPort, stationList.get(i+1), downStreamPort);
		}
		
		for(int i=0; i< stationList.size();i++){
			String ctrlPort = MartaConst.STATION_MODEL_CTRL_PORT_NAME_PREFIX + stationList.get(i).getStationNum();
			this.addCoupling(stationList.get(i), ctrlPort , center, "scheduleIn");
		}
		
		this.addCoupling(center, "scheduleOut", stationList.get(0), MartaConst.STATION_MODEL_IN_PORT_NAME_PREFIX+stationList.get(0).getStationNum());
		this.addCoupling(center, "send", r, "Demo");
	}
	
	
	
	public static void main(String args[]) {
		MartaSystem s = new MartaSystem("test");
	}
 
   
}
